#include "sunlight.h"
#include <QDebug>
#include <QFile>
#include <QStringList>

SunLight::SunLight()
{
}

bool SunLight::load(const QString fileName)
{
    clear();
    QString fileData = "";

    QFile file(fileName);
    if (!file.open(QIODevice::ReadOnly)) {
        return false;
    }
    QTextStream stream(&file);
    fileData = stream.readAll();
    file.close();

    QStringList lines = fileData.split('\n');
    for (int i=0; i<lines.count(); i++) {
        qDebug() << lines[i];
        QStringList days = lines[i].split(',');
        if (3 <= days.count()) {
            DayInfo dayInfo;

            dayInfo.mDate = QDate::fromString(days[0], "MM-dd");
            dayInfo.mTimeSunRise = QTime::fromString(days[1], "hh:mm");
            dayInfo.mTimeSunSet = QTime::fromString(days[2], "hh:mm");

            mMapDays.insert(days[0], dayInfo);
        }
    }
    qDebug() << "mDays.count() :" << mMapDays.count();

    return true;
}

void SunLight::clear()
{
    mMapDays.clear();
}
